package bg.bgfirst;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import bg.bgfirst.storage.DatabaseHandler;


import android.app.Application;

public class ApplicationBg extends Application {

	public static final String BG_UNKNOWN_="Unknown";
	private int ringerMode_Z_1 = 0;
	//private List<String> blackList = new ArrayList<String>();
	private HashMap<String, String> hBlackList = new HashMap<String, String>();
	private boolean modeSilent;
	
	private DatabaseHandler dbHelper;
	
	public int getRingerMode_Z_1() {
		return ringerMode_Z_1;
	}

	public void setRingerMode_Z_1(int ringerMode_Z_1) {
		this.ringerMode_Z_1 = ringerMode_Z_1;
	}

	

	public boolean isModeSilent() {
		return modeSilent;
	}

	public void setModeSilent(boolean modeSilent) {
		this.modeSilent = modeSilent;
	}
	
	public boolean isBlackListed(String numero) {
		if (numero == null){
			numero = BG_UNKNOWN_;
		}
		return !(this.hBlackList.get(numero)==null);
	}

	public HashMap<String, String> gethBlackList() {
		return hBlackList;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		this.dbHelper= new DatabaseHandler(this);
		this.dbHelper.getWritableDatabase();
		this.hBlackList = dbHelper.getMap();
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
		
	}
	
	public void persist() {
		dbHelper.clear();
		for(String s : this.hBlackList.keySet()){
			String numero = s;
			String contactName = hBlackList.get(numero);
			dbHelper.addContact(numero, contactName);
		}
	}

	
	

}
